﻿using QuarryPlanner.Domain.DTOs;
using System.Data.Entity;

namespace QuarryPlanner.Persistence.Config
{
    // Author: Ryan Redburn
    // Created: 10/20/2014

    #region [ Updates ]

    // Author: Ryan Redburn
    // Date: 12/3/2014
    // Revision: Added column mappings for the MobileVehicleExam and WorkPlaceExam.

    #endregion

    /// <summary>
    /// Data context class used by the Entity Framework for the QRP project.
    /// </summary>
    public class QRPContext : DbContext
    {
        public virtual DbSet<QuarryHoursDTO> QuarryHours { get; set; }
        public virtual DbSet<MobileVehicleExamDTO> MobileVehicleExams { get; set; }
        public virtual DbSet<WorkPlaceExamDTO> WorkPlaceExams { get; set; }

        public QRPContext() : base("name=QRPContext") { }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Table and primary key mappings
            modelBuilder.Entity<QuarryHoursDTO>().ToTable("QuarryHours").HasKey(k => k.QuarryHoursID);
            modelBuilder.Entity<MobileVehicleExamDTO>().ToTable("MobileVehicleExam").HasKey(k => k.MobileVehicleExamID);
            modelBuilder.Entity<WorkPlaceExamDTO>().ToTable("WorkPlaceExam").HasKey(k => k.WorkPlaceExamID);

            // MobileVehicleExam column mappings
            modelBuilder.Entity<MobileVehicleExamDTO>().Property(x => x.International).HasColumnName("87International");
            modelBuilder.Entity<MobileVehicleExamDTO>().Property(x => x.Loader).HasColumnName("988Loader");
            modelBuilder.Entity<MobileVehicleExamDTO>().Property(x => x.THForkLift).HasColumnName("TH62ForkLift");
            modelBuilder.Entity<MobileVehicleExamDTO>().Property(x => x.TLForkLift).HasColumnName("TL943ForkLift");
            modelBuilder.Entity<MobileVehicleExamDTO>().Property(x => x.Truck).HasColumnName("99F450");

            // WorkPlaceExamMappings
            modelBuilder.Entity<WorkPlaceExamDTO>().Property(x => x.FiveFootSaw).HasColumnName("5Saw");
            modelBuilder.Entity<WorkPlaceExamDTO>().Property(x => x.SevenFootSaw).HasColumnName("7Saw");
        }
    }
}
